package com.dcits.electronic_account.controller;

import com.dcits.electronic_account.bean.ResponseJson;
import com.dcits.electronic_account.constant.Constant;
import com.dcits.electronic_account.service.VirtualBanlanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;


/**
 * @Author: 周智鑫
 * @Date： 2022/6/26
 */
@RestController
@RequestMapping("/virtual_account")
public class VirtualAccountController {
    @Autowired
    private VirtualBanlanceService banlanceService;

    @GetMapping("/{id}")
    public ResponseJson virtualBalance(@PathVariable("id") Integer id){
        //查询虚拟账户余额
        BigDecimal result = banlanceService.selcetVirtualBanlance(id);
        //先将该值转换为String类型，然后判断是否为null，不为null则返回数值，为null则返回0
        String s = String.valueOf(result);
        if(!"null".equals(s)){
            return new ResponseJson(Constant.SUCCESS_CODE,result);
        }
        return new ResponseJson(Constant.SUCCESS_CODE,0);
    }
}
